package com.example.idachuappone.person.method;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.example.idachuappone.person.entity.Order;
import com.example.idachuappone.utils.NetUtil;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

public class OrderMethod {

	public static interface SetOrder {
		void onFail();

		void onSuccess(String str);
	}

	public static interface SetOrderList {
		void onFail();

		void onSuccess(List<Order> list, String str);
	}

	static class AnonymousClass_1 extends RequestCallBack<String> {
		private final/* synthetic */SetOrderList val$setOrderList;

		AnonymousClass_1(SetOrderList setOrderList) {
			this.val$setOrderList = setOrderList;
		}

		@Override
		public void onSuccess(ResponseInfo<String> responseInfo) {
			try {
				JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicode(responseInfo.result));
				if (jsonObject.getInt("code") == 10000) {
					List<Order> list = new ArrayList();
					JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("result");
					for (int i = 0; i < jsonArray.length(); i++) {
						list.add(new Order().parseJson(jsonArray.getJSONObject(i)));
					}
					this.val$setOrderList.onSuccess(list, NetUtil.unescapeUnicode(responseInfo.result));
					return;
				}
				this.val$setOrderList.onSuccess(null, NetUtil.unescapeUnicode(responseInfo.result));
			} catch (JSONException e) {
				e.printStackTrace();
				this.val$setOrderList.onSuccess(null, "");
			}
		}

		@Override
		public void onFailure(HttpException arg0, String arg1) {
			this.val$setOrderList.onFail();
		}
	}

	public static void getOrderList(Context context, String path, SetOrderList setOrderList) {
		NetUtil.get(context, path, 100, new AnonymousClass_1(setOrderList));
	}
}
